package com.briup.jz.service.impl;

import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.AccountSystemExample;
import com.briup.jz.dao.AccountSystemMapper;
import com.briup.jz.service.AccountSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AccountSystemServiceImpl implements AccountSystemService {

  @Autowired private AccountSystemMapper accountSystemMapper;

  @Override
  public void saveOrUpdate(AccountSystem accountSystem) {
    if (accountSystem.getId() != null) {
      accountSystem.setTransferTime(new Date().getTime());
      accountSystemMapper.updateByPrimaryKey(accountSystem);
    } else {
      accountSystem.setTransferTime(new Date().getTime());
      accountSystemMapper.insert(accountSystem);
    }
  }

  @Override
  public void deleteById(long id) {
    accountSystemMapper.deleteByPrimaryKey(id);
  }

  @Override
  public AccountSystem queryAccountSystemById(long id) {

    return accountSystemMapper.selectByPrimaryKey(id);
  }

  @Override
  public List<AccountSystem> query(String type, String status) {
    AccountSystemExample example = new AccountSystemExample();
    AccountSystemExample.Criteria criteria = example.createCriteria();
    if (type != null) {
      criteria.andTypeEqualTo(type);
    }
    if (status != null) {
      criteria.andStatusEqualTo(status);
    }

    List<AccountSystem> list = accountSystemMapper.selectByExample(example);
    return list;
  }
}
